package com.sgdh.project.terminal.program.controller;

import java.util.List;
import java.util.stream.Collectors;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.sgdh.common.utils.StringUtils;
import com.sgdh.common.utils.security.ShiroUtils;
import com.sgdh.framework.aspectj.lang.annotation.Log;
import com.sgdh.framework.aspectj.lang.enums.BusinessType;
import com.sgdh.framework.web.controller.BaseController;
import com.sgdh.framework.web.domain.AjaxResult;
import com.sgdh.framework.web.page.TableDataInfo;
import com.sgdh.project.terminal.program.domain.Program;
import com.sgdh.project.terminal.program.service.IProgramService;

/**
 * 项目信息管理
 * 
 * @author px
 */
@Controller
@RequestMapping("/sks/program")
public class ProgramController extends BaseController
{
    private String prefix = "sks/program";

    @Autowired
    private IProgramService programService;


    @RequiresPermissions("sks:program:view")
    @GetMapping()
    public String program()
    {
        return prefix + "/program";
    }

    @RequiresPermissions("sks:program:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Program program)
    {
        startPage();
        List<Program> list = programService.selectProgramList(program);
        return getDataTable(list);
    }


    /**
     * 新增项目
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目
     */
    @RequiresPermissions("sks:program:add")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated Program program)
    {
        return toAjax(programService.insertProgram(program));
    }

    /**
     * 修改项目
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") int id, ModelMap mmap)
    {
        mmap.put("program", programService.selectProgramById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存项目
     */
    @RequiresPermissions("sks:program:edit")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated Program program)
    {
        return toAjax(programService.updateProgram(program));
    }


    @RequiresPermissions("sks:program:remove")
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(programService.deleteProgramByIds(ids));
    }

}